// pages/operat/fleedTools/inStorage/scanCode/scanCode.js
const LApp = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    myDate: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var info = {};
    if (options.code != undefined) {
      let code = [options.code];
      if (code) {
        info.Codes = code;
        info.Num = code.length;
        info.ProductID = options.ProductId
      }
    } else {
      info.Codes = null;
      info.Num = 0;
      info.ProductID = 0
    }
    this.setData({
      info: info
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];
    if (this.data.myDate == 1) {
      this.setData({
        info: {}
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  continueOper: function () {    
    let that = this;
    wx.scanCode({
      success: (res) => {
        var codes = that.data.info.Codes;
        if (codes)
        {
          if (codes.indexOf(res.result) > -1) {
            wx.showToast({
              title: "该码已重复扫描",
            })
            return
          }
          }
        if (!that.data.info.ProductID) { that.data.info.ProductID=0}
        LApp._get({
          url: 'nbapi/fleedtool/dh/check',
          data: { code: res.result, userId: LApp.globalData.userInfo.UserID, proId: that.data.info.ProductID },
          success: function (r) {
            if (r) {
              if (codes == null) codes = [];
              codes.push(res.result);
              var Info = {};
              Info.Codes = codes;
              Info.Num = Info.Codes.length;
              that.setData({
                info: Info
              })
            }
            else {
              wx.showToast({
                title: r,
              })
            }
          }
        })

      }
    })
  },
  relationInfo: function () {
    let _this = this;
   // _this.data.info.FormCode = 'DH' + new Date().getTime();
        //页面传值并跳转
        if (_this.data.info) {
          LApp.pages.add(_this);
          wx.navigateTo({
            url: '../transferGoodsApply/transferGoodsApply',
          })
        }
  },
  // relationInfo:function()
  // {
  //   let _this = this;
  //   LApp._get({
  //     url: "nbapi/fleedtool/getinfo/formcode",
  //     data: { formType: 'DH', enterpriseId: LApp.globalData.userInfo.EnterpriseId },
  //     success: function (res) {
  //       console.log(res);
  //       _this.data.info.FormCode = res;
  //       //页面传值并跳转
  //       if (_this.data.info) {     
  //         LApp.pages.add(_this);
  //         wx.navigateTo({
  //           url: '../transferGoodsApply/transferGoodsApply',
  //         })
  //       }
  //     }
  //   })
  // },
})